from my_sklearn import load_iris, train_test_split, SimpleMyKNeighborsClassifier
from sklearn.neighbors import KNeighborsClassifier

# 加载数据
iris = load_iris()
# 分离训练集和测试集
X = iris.data
y = iris.target

# 分离训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.9, random_state=4563456)

# 输出测试集标签
print("y_test", y_test)

# 邻居数量
n_neighbors = 15

# 定义 sklearn KNN 算法 对象
kNeighborsClassifier = KNeighborsClassifier(n_neighbors=n_neighbors)
# 训练分类器
kNeighborsClassifier.fit(X_train, y_train)
# 预测
kNeighborsClassifier_y_pred = kNeighborsClassifier.predict(X_test)
# 输出 sklearn 预测
print('sklearn 预测', kNeighborsClassifier_y_pred.tolist())

# 定义 简单 KNN 算法 对象
simpleMyKNeighborsClassifier = SimpleMyKNeighborsClassifier(n_neighbors=n_neighbors)
# 训练分类器
simpleMyKNeighborsClassifier.fit(X_train, y_train)
# 预测
simpleMyKNeighborsClassifier_y_pred = simpleMyKNeighborsClassifier.predict(X_test)
# 输出 自己实现的预测
print('自己实现的预测', simpleMyKNeighborsClassifier_y_pred)

# 输出两种实现方式的对比
print('两种实现方法结果对比：',
      '一致' if str(kNeighborsClassifier_y_pred.tolist()) == str(simpleMyKNeighborsClassifier_y_pred) else '不一致')
